<?php
require_once("connect_db.php");
if(!isset($_POST["temp"])||empty($_POST["temp"])){
$sqlGen="SELECT teach_id FROM teacher ORDER BY teach_id DESC LIMIT 1";
$queryGen=mysql_query($sqlGen,$conn);
$resultGen=mysql_fetch_array($queryGen);
$number =(int)substr($resultGen["teach_id"],1);
$id="t".str_pad(($number+1),4,"0",STR_PAD_LEFT );
$sqlRegister="INSERT INTO teacher(teach_id,teach_name,teach_lname,teach_birthdate,teach_sex,teach_tel,";
$sqlRegister.="teach_mail,teach_address,teach_code,teach_pic,user_name,password,role,status) VALUES(";
$sqlRegister.="'".$id."','".$_POST["teach_name"]."','".$_POST["teach_lname"]."','".$_POST["teach_birth"]."'";
$sqlRegister.=",'".$_POST["teach_sex"]."','".$_POST["teach_tel"]."','".$_POST["teach_email"]."','".$_POST["teach_addr"]."'";
$sqlRegister.=",'".$_POST["teach_code"]."','".$_POST["pics"]."','".$_POST["user_name"]."','".$_POST["vpassword"]."'";
$sqlRegister.=",'teacher','Y')";
$queryRegister=mysql_query($sqlRegister,$conn);}

else{
$sqlUpdate="update teacher set teach_name='".$_POST["teach_name"]."',teach_lname='".$_POST["teach_lname"]."',
			teach_birthdate='".$_POST["teach_birth"]."',teach_sex='".$_POST["teach_sex"]."',teach_tel='".$_POST["teach_tel"]."',
			teach_mail='".$_POST["teach_email"]."',teach_address='".$_POST["teach_addr"]."',teach_code='".$_POST["teach_code"]."',
			teach_pic='".$_POST["pics"]."',user_name='".$_POST["user_name"]."',password='".$_POST["vpassword"]."'
			where teach_id='".$_POST["temp"]."'";
		$queryUpdate=mysql_query($sqlUpdate);
}

?>